package ui

import (
	"github.com/mattn/go-gtk/gtk"
)

func LoginUI() {

	builder := gtk.NewBuilder()
	builder.AddFromFile("K:\\LTYBlockChain\\src\\ui\\login.glade")
	win := gtk.WindowFromObject(builder.GetObject("window1"))

	entry1 := gtk.EntryFromObject(builder.GetObject("entry1"))
	entry2 := gtk.EntryFromObject(builder.GetObject("entry2"))

	//注册按钮
	b1 := gtk.ButtonFromObject(builder.GetObject("button1"))
	b1.Clicked(func() {

		builder2 := gtk.NewBuilder()
		builder2.AddFromFile("K:\\LTYBlockChain\\src\\ui\\register.glade")
		dlg := gtk.WidgetFromObject(builder.GetObject("dialog1"))

		entry1 := gtk.EntryFromObject(builder.GetObject("entry1"))
		entry2 := gtk.EntryFromObject(builder.GetObject("entry2"))
		entry3 := gtk.EntryFromObject(builder.GetObject("entry3"))
		entry4 := gtk.EntryFromObject(builder.GetObject("entry4"))
		name := entry1.GetText()
		password := entry2.GetText()
		phone := entry3.GetText()
		email := entry4.GetText()

		b1 := gtk.ButtonFromObject(builder.GetObject("button1"))
		b2 := gtk.ButtonFromObject(builder.GetObject("button2"))

		b1.Clicked(func() {
			if name == "" || password == "" || phone == "" || email == "" {
				warn := gtk.NewMessageDialog(
					win,
					gtk.DIALOG_MODAL,
					gtk.MESSAGE_WARNING,
					gtk.BUTTONS_OK,
					"不能为空")
				warn.Run()
				warn.Destroy()
			}
		})

		b2.Clicked(func() {

		})

		dlg.Show()

	})

	//登录按钮
	b2 := gtk.ButtonFromObject(builder.GetObject("button2"))
	b2.Clicked(func() {
		name := entry1.GetText()
		password := entry2.GetText()
		if name == "" || password == "" {

		}
	})

	win.Show()
}

func login() {

}

func register(name string) bool {
	return false
}
